Ext.define('Seq.Array', {
    singleton: true,

    times: function (interval, format, start, end, step) { // 一般为全天时间，所以start end参数一般不填
        start = start ? new Date(start) : new Date(Ext.Date.format(new Date(), 'Y-m-d 00:00:00'));
        end = end ? new Date(end) : Ext.Date.add(start, Ext.Date.DAY, 1);
        interval = interval ? interval : 5;
        format = format ? format : 'H:i';

        var result = [];
        while (start < end) {
            result.push(Ext.util.Format.date(start, format));
            start = Ext.Date.add(start, step ? step : Ext.Date.MINUTE, interval);
        }
        return result;
    },

    dates: function (interval, format, start, end) {
        return this.times(interval, format ? format : 'Y-m-d', start, end, Ext.Date.DAY);
    },

    minutes: function (interval, format, start, end) { // 后台Period别名
        return this.times(interval, format, start, end);
    },

    hours: function (interval, format, start, end) { // 后台Period别名
        return this.times(interval * 60, format, start, end);
    },

    days: function (interval, format, start, end) { // 后台Period别名
        return this.dates(interval, format, start, end);
    },

    months: function (interval, format, start, end) { // 后台Period别名
        return this.times(interval, format ? format : 'Y-m-d', start, end, Ext.Date.MONTH);
    },

    numbers: function (interval, format, start, end, divisor) {
        interval = interval ? interval : 1;
        divisor = divisor ? divisor : 1;
        format = format ? format : '0.#';
        var result = [];
        while (start <= end) {
            result.push(Ext.util.Format.number(start / divisor, format));
            start += interval;
        }
        return result;
    },

    applyIf(array, p) {
        for (let m in p) {
            for (let item of array) {
                let n = item[m];
                if (Ext.isArray(n)) {
                    for (let k of n) {
                        Ext.applyIf(k, p[m]);
                    }
                } else {
                    if (undefined == n) {
                        item[m] = p[m];
                    }
                }
            }
        }
        return array;
    }
});